package com.lk.netty.handler;

import com.lk.netty.encode.UserMessageDecode;
import com.lk.netty.encode.UserMessageEncode;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;
import org.bouncycastle.util.test.Test;

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Map;

/**
 * 服务端初始化
 */
public class ServerInitializer extends ChannelInitializer<SocketChannel> {


    public ServerInitializer() {
        System.out.println("ServerInitializer");
    }

    @Override
    public void initChannel(SocketChannel ch) {

        ChannelPipeline pipeline = ch.pipeline();

//        pipeline.addLast(new StringDecoder());
//        pipeline.addLast(new StringEncoder());
//        pipeline.addLast(new UserMessageDecode());
//        pipeline.addLast(new UserMessageEncode());
//
        pipeline.addLast(new LoggingHandler(LogLevel.DEBUG));
//        pipeline.addLast(new StringHandler());
//        pipeline.addLast(new TestHandler());
//        ch.pipeline().addLast(new TestHandler());
        pipeline.addLast(new ServerHandler());
        pipeline.addLast(new StringEncoder(StandardCharsets.UTF_8));
        pipeline.addLast(new StringDecoder(StandardCharsets.UTF_8));
//        ch.pipeline().addLast(new AuthHandler());
    }
}
